<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/22 0022
 * Time: 11:50
 */

namespace app\home\controller\user;
use app\home\controller\Base;
use app\home\service\CodeService;

class Message extends Base
{
    public function message(){
        $dealerInfo=parent::is_Login();
        if(!$dealerInfo){
            return CodeService::AUTH_TIMEOUT;
        }
        $state      =input('state');
        $page       =input('page');
        $list_row   =input('list_row');
        $page    =!empty($page)?$page:1;
        $list_row=!empty($list_row)?$list_row:15;
        $state   =!empty($state)?$state:1;
        $u_id    =$dealerInfo['u_id'];
        $Message=new \app\home\model\dealer\Message();

        $where['u_id']      =$u_id;
        $where['state']     =$state;
        $Message->page      =$page;
        $Message->pageNum   =$list_row;
        $Message->order     ="create_time desc";
        $rel                =$Message->getPageList($where);
        return CodeService::response(200,CodeService::SUCCESS,$rel);
    }
    public function redmsg(){
        $dealerInfo=parent::is_Login();
        if(!$dealerInfo){
            return CodeService::AUTH_TIMEOUT;
        }
        $Message=new \app\home\model\dealer\Message();
        $m_c=$Message->where(["u_id"=>$dealerInfo['u_id']])->count();
        $rel=['status'=>($m_c > 0)?1:0];
        return CodeService::response(200,CodeService::SUCCESS,$rel);
    }

    public function red(){
        $msg_id = input('msg_id');
        if(empty($msg_id)){
            return CodeService::PARAMETER_EXCEPTION;
        }
        $Message=new \app\home\model\dealer\Message();
        $Message->where(["msg_id"=>$msg_id])->setField('read',1);
        return CodeService::response(200,CodeService::SUCCESS);
    }
}